
Create database QLK
use QLK
create table login(
	Usename varchar(15) constraint FK_login primary key,
	Password varchar(15),
	[Status] varchar(10)
)
----
go
Create table ChungLoai(
	MaCL varchar(20) constraint PK_ChungLoai primary key,
	TenCL nvarchar(25)
)
----
go
create table NCC(
	MaNCC varchar(10) constraint PK_NCC primary key,
	TenNCC nvarchar(25),
	DiaChi nvarchar(50),
	Masothue varchar(10),
	SoTK varchar(10)	
)
go
Create table HangHoa(
	MaHang varchar(10) constraint PK_hanghoa primary key,
	TenHang varchar(25),
	ChungLoai varchar(20) constraint FK_ChungLoai foreign key references ChungLoai,
	DonGia float,
	DVtinh varchar(5),
	HSD varchar(10),
	Soluong int	
)

go
Create table Kho
(	
	MaKho varchar(10) constraint PK_Kho primary key,
	TenKho varchar(20),
	DiaChi nvarchar(40)
)
go
Create table NhanVien(
	MaNV varchar(10) constraint PK_NhanVien primary key,
	TenNV nvarchar(40),
	ChucVu varchar(10),
	GioiTinh varchar(3)
)
go
Create table KhachHang(
	MaKH varchar(10) constraint PK_KhachHang primary key,
	TenKH nvarchar(40),
	GioiTinh varchar(3),
	DiaChi nvarchar(40),
	DienThoai varchar(10),
)


go
Create table ThuKho(
	MaTK varchar(10) constraint PK_ThuKho primary key,
	TenTK nvarchar(20)
)
go
Create table HoaDonNhap(
	MaHang varchar(10) constraint FK_HangHoa foreign key references HangHoa,
	SoHDN varchar(10) constraint PK_HoaDonNhap primary key,
	DonGia float,
	SoLuong int,
	ThueVAT float
)
go
Create table CungCapHang(
	MaNCC varchar(10) constraint FK_NCC foreign key references NCC,
	SoHDN varchar(10) constraint FK_HoaDonNhap foreign key references HoaDonNhap,
	NgayCC varchar(10)
)
go
Create table ThanhToan(
	MaNV varchar(10) constraint FK_NhanVien foreign key references NhanVien,
	MaNCC varchar(10) constraint FK1_NCC foreign key references NCC,
	SoPhieuChi varchar(10) constraint PK_ThanhToan primary key,
	NgayChi varchar(10),
	LyDo varchar(40),
	XacNhan nvarchar(30)
)
go
Create table PhieuNhap(
	MaHang varchar(10) constraint FK1_HangHoa foreign key references HangHoa,
	SoPhieuNhap varchar(10) constraint PK_PhieuNhap primary key,
	SoLuongYeuCau int,
	SoLuongThuc int,
	NgayNhap varchar(10)
)
Create table HangNhap(
	SoPhieuNhap varchar(10) constraint FK_PhieuNhap references PhieuNhap,
	MaKho varchar(10),
	NgayNhap varchar(10),
	MaTK varchar(10)
)
Create table PhieuXuat(
	MaHang varchar(10),
	SoPhieu varchar(10) constraint PK_PhieuXuat primary key,
	SoLuongXuat int,
	NgayXuat varchar(10),
	MaKH varchar(10) constraint FK_KhachHang foreign key references KhachHang
)
go
Create table HoaDonXuat(
	MaHang varchar(10),
	SoHDX varchar(10) constraint PK_HoaDonXuat primary key,
	DonGia float,
	SoLuong int,
	ThueVAT float
)
go
Create table XuatHang(
	MaKH varchar(10) constraint FK1_KhachHang foreign key references KhachHang,
	SoHDX varchar(10) constraint FK_HoaDonXuat foreign key references HoaDonXuat,
	NgayCC varchar(10)
)
go
Create table HangXuat(
	MaNV varchar(10),
	SoPhieu varchar(10) constraint FK_PhieuXuat foreign key  references PhieuXuat,
	NgayXuat varchar(10),
	MaTK varchar(10)
)

































